Imports MetaView.AnnotatedImage
Public Class AnnotationContainerProperties
  Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

  Public Sub New()
    MyBase.New()

    'This call is required by the Windows Form Designer.
    InitializeComponent()

    'Add any initialization after the InitializeComponent() call

    'We make sure the color and opacity are synchronized
    Me.pnlColor.BackColor = Color.FromArgb(Me.trkOpacity.Value, Me.pnlColor.BackColor)

  End Sub

  'Form overrides dispose to clean up the component list.
  Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
    If disposing Then
      If Not (components Is Nothing) Then
        components.Dispose()
      End If
    End If
    MyBase.Dispose(disposing)
  End Sub

  'Required by the Windows Form Designer
  Private components As System.ComponentModel.IContainer

  'NOTE: The following procedure is required by the Windows Form Designer
  'It can be modified using the Windows Form Designer.  
  'Do not modify it using the code editor.
  Friend WithEvents btnColor As System.Windows.Forms.Button
  Friend WithEvents pnlColor As System.Windows.Forms.Panel
  Friend WithEvents txtText As System.Windows.Forms.TextBox
  Friend WithEvents chkVisible As System.Windows.Forms.CheckBox
  Friend WithEvents Label3 As System.Windows.Forms.Label
  Friend WithEvents Label1 As System.Windows.Forms.Label
  Friend WithEvents btnCancel As System.Windows.Forms.Button
  Friend WithEvents btnOk As System.Windows.Forms.Button
  Friend WithEvents txtKey As System.Windows.Forms.TextBox
  Friend WithEvents Label7 As System.Windows.Forms.Label
  Friend WithEvents trkOpacity As System.Windows.Forms.TrackBar
  Friend WithEvents AnnColorDialog As System.Windows.Forms.ColorDialog
  <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.btnColor = New System.Windows.Forms.Button
        Me.pnlColor = New System.Windows.Forms.Panel
        Me.txtText = New System.Windows.Forms.TextBox
        Me.chkVisible = New System.Windows.Forms.CheckBox
        Me.Label3 = New System.Windows.Forms.Label
        Me.Label1 = New System.Windows.Forms.Label
        Me.btnCancel = New System.Windows.Forms.Button
        Me.btnOk = New System.Windows.Forms.Button
        Me.txtKey = New System.Windows.Forms.TextBox
        Me.Label7 = New System.Windows.Forms.Label
        Me.trkOpacity = New System.Windows.Forms.TrackBar
        Me.AnnColorDialog = New System.Windows.Forms.ColorDialog
        CType(Me.trkOpacity, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'btnColor
        '
        Me.btnColor.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnColor.Location = New System.Drawing.Point(169, 58)
        Me.btnColor.Name = "btnColor"
        Me.btnColor.Size = New System.Drawing.Size(69, 21)
        Me.btnColor.TabIndex = 38
        Me.btnColor.Text = "Select"
        '
        'pnlColor
        '
        Me.pnlColor.BackColor = System.Drawing.Color.Red
        Me.pnlColor.Location = New System.Drawing.Point(136, 58)
        Me.pnlColor.Name = "pnlColor"
        Me.pnlColor.Size = New System.Drawing.Size(22, 21)
        Me.pnlColor.TabIndex = 37
        '
        'txtText
        '
        Me.txtText.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.txtText.Location = New System.Drawing.Point(136, 93)
        Me.txtText.Name = "txtText"
        Me.txtText.Size = New System.Drawing.Size(271, 20)
        Me.txtText.TabIndex = 36
        '
        'chkVisible
        '
        Me.chkVisible.CheckAlign = System.Drawing.ContentAlignment.MiddleRight
        Me.chkVisible.Checked = True
        Me.chkVisible.CheckState = System.Windows.Forms.CheckState.Checked
        Me.chkVisible.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.chkVisible.Location = New System.Drawing.Point(8, 34)
        Me.chkVisible.Name = "chkVisible"
        Me.chkVisible.Size = New System.Drawing.Size(138, 24)
        Me.chkVisible.TabIndex = 35
        Me.chkVisible.Text = "Visible"
        '
        'Label3
        '
        Me.Label3.Location = New System.Drawing.Point(7, 95)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(62, 16)
        Me.Label3.TabIndex = 33
        Me.Label3.Text = "Text"
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(8, 66)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(128, 16)
        Me.Label1.TabIndex = 32
        Me.Label1.Text = "Color and opacity"
        '
        'btnCancel
        '
        Me.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.btnCancel.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnCancel.Location = New System.Drawing.Point(217, 122)
        Me.btnCancel.Name = "btnCancel"
        Me.btnCancel.Size = New System.Drawing.Size(64, 32)
        Me.btnCancel.TabIndex = 40
        Me.btnCancel.Text = "Cancel"
        '
        'btnOk
        '
        Me.btnOk.DialogResult = System.Windows.Forms.DialogResult.OK
        Me.btnOk.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnOk.Location = New System.Drawing.Point(129, 122)
        Me.btnOk.Name = "btnOk"
        Me.btnOk.Size = New System.Drawing.Size(64, 32)
        Me.btnOk.TabIndex = 39
        Me.btnOk.Text = "Ok"
        '
        'txtKey
        '
        Me.txtKey.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.txtKey.Enabled = False
        Me.txtKey.Location = New System.Drawing.Point(135, 10)
        Me.txtKey.Name = "txtKey"
        Me.txtKey.Size = New System.Drawing.Size(272, 20)
        Me.txtKey.TabIndex = 46
        '
        'Label7
        '
        Me.Label7.Location = New System.Drawing.Point(8, 11)
        Me.Label7.Name = "Label7"
        Me.Label7.Size = New System.Drawing.Size(114, 16)
        Me.Label7.TabIndex = 45
        Me.Label7.Text = "Unique Key or Name"
        '
        'trkOpacity
        '
        Me.trkOpacity.AutoSize = False
        Me.trkOpacity.LargeChange = 32
        Me.trkOpacity.Location = New System.Drawing.Point(245, 59)
        Me.trkOpacity.Maximum = 255
        Me.trkOpacity.Name = "trkOpacity"
        Me.trkOpacity.Size = New System.Drawing.Size(166, 20)
        Me.trkOpacity.TabIndex = 47
        Me.trkOpacity.TickFrequency = 32
        Me.trkOpacity.Value = 31
        '
        'AnnColorDialog
        '
        Me.AnnColorDialog.AnyColor = True
        '
        'AnnotationContainerProperties
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(411, 158)
        Me.Controls.Add(Me.trkOpacity)
        Me.Controls.Add(Me.txtKey)
        Me.Controls.Add(Me.txtText)
        Me.Controls.Add(Me.Label7)
        Me.Controls.Add(Me.btnCancel)
        Me.Controls.Add(Me.btnOk)
        Me.Controls.Add(Me.btnColor)
        Me.Controls.Add(Me.pnlColor)
        Me.Controls.Add(Me.chkVisible)
        Me.Controls.Add(Me.Label3)
        Me.Controls.Add(Me.Label1)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow
        Me.Name = "AnnotationContainerProperties"
        Me.Text = "ROI container properties"
        CType(Me.trkOpacity, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub

#End Region

  Private Sub AnnotationContainerProperties_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

  End Sub

  Public Sub SetDialogNewProperties()
    txtKey.Enabled = True
  End Sub

  Public Sub SetDialogProperties(ByVal oAnn As AnnotationContainer)
    'Set all the dialog properties using the annotation container values
    txtText.Text = oAnn.Text
    chkVisible.Checked = oAnn.Visible
    trkOpacity.Value = oAnn.Color.A
    pnlColor.BackColor = oAnn.Color
    txtKey.Text = oAnn.Key
  End Sub

  Public Overloads Sub SetAnnotationProperties(ByVal oAnn As AnnotationContainer)
    'Set all the properties using the dialog values
    oAnn.Color = pnlColor.BackColor
    oAnn.Text = txtText.Text
    oAnn.Visible = chkVisible.Checked
  End Sub

  Private Sub btnColor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnColor.Click
        If AnnColorDialog.ShowDialog() = Windows.Forms.DialogResult.OK Then
            pnlColor.BackColor = Color.FromArgb(trkOpacity.Value, AnnColorDialog.Color)
        End If
  End Sub

  Public Overloads Function SetAnnotationProperties(ByVal oAnnContainers As AnnotationContainerCollection) As AnnotationContainer
    'Use when creating a new container
    Dim strKey As String
    If txtKey.TextLength > 0 Then
      strKey = txtKey.Text
    Else
      Dim iID As Integer = 1
      Do While oAnnContainers.KeyExists("Container " & iID)
        iID = iID + 1
      Loop
      strKey = "Container " & iID
    End If
    Dim oAnnCon As New AnnotationContainer
    oAnnContainers.Add(oAnnCon, strKey)
    SetAnnotationProperties(oAnnCon)
    Return oAnnCon
  End Function

  Private Sub trkOpacity_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles trkOpacity.ValueChanged
    'Change opacity of color in panel
    pnlColor.BackColor = Color.FromArgb(trkOpacity.Value, pnlColor.BackColor)
  End Sub

  Private Sub txtKey_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtKey.TextChanged
    'Key is used as text
    txtText.Text = txtKey.Text
  End Sub
End Class
